package com.bdqn.blog.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.bdqn.blog.entity.Admin;
import com.bdqn.blog.service.impl.AdminServiceImpl;
import com.bdqn.blog.util.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import org.springframework.stereotype.Controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 管理员 前端控制器
 * </p>
 *
 * @author 阿桐幕
 * @since 2020-10-29
 */
@RestController
public class AdminController {

    @Autowired
    AdminServiceImpl adminService;

    /**
     *  登录验证
     * **/
    @PostMapping("/admin/login")
    public Map<String, Object> login(@RequestBody Admin admin){

        QueryWrapper<Admin> wrapper = new QueryWrapper<>();
        wrapper
                .eq("name",admin.getName())
                .eq("password",admin.getPassword());
        Admin admin1 = adminService.getOne(wrapper);
        Map<String, Object> map = new HashMap<>();
        if (admin1 != null ){
            map.put("msg","succeed");
            map.put("data",admin1);
        }else {
            map.put("msg","fail");
        }
        return map;
    }


}

